import { PORTS } from '../config/ports.js';

// 使用统一端口配置
const HTTP_PORT = PORTS.HTTP;
const WS_PORT = PORTS.WEBSOCKET;

// 端口范围（用于备用方案）
const startPort = 8000;
const endPort = 8010;
import crypto from 'crypto';

function getRandomColor() {
    let color = '#' + Math.floor(Math.random() * 16777215).toString(16);
    // 确保颜色字符串长度为6位，不足时前面补0
    color = color.padEnd(7, '0'); // `#`占一位，加上不足的`0`
    return color;
}

function getUUID() {
    const array = new Uint8Array(16);
    crypto.randomFillSync(array);

    // 按照 UUID v4 的规则修改特定位
    array[6] = (array[6] & 0x0f) | 0x40; // 第7字节设置为0100xxxx
    array[8] = (array[8] & 0x3f) | 0x80; // 第9字节设置为10xxxxxx

    return Array.from(array)
        .map(b => b.toString(16).padStart(2, '0'))
        .join('')
        .replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '$1-$2-$3-$4-$5');
}

export {
    startPort,
    endPort,
    HTTP_PORT,
    WS_PORT,
    getRandomColor,
    getUUID
};